// IRGenerator.h - IR生成器核心
#pragma once
#include "Module.h"
#include "IRbuilder.h"
#include "SymbolTable.h"
#include "AST.h"
#include "Type.h"
#include "IRprinter.h"
#include <variant>
#include "utils.h"
#include "AST_process.h"


void visitInitVarDef(ASTNode *ctx, SymbolTable *s, Module *m, BasicBlock* bb=nullptr, bool isGlobal=true, bool isConst=false);
void visitChildren(ASTNode *ctx, SymbolTable *s, Module *m, string &type, string &var_name, variant<int, string> &data);

void visitBType(ASTNode *ctx, string &type);
void visitIdent(ASTNode *ctx, string &var_name);
void visitNumber(ASTNode *ctx, variant<int, string> &data);

void visitAssignExp(ASTNode *ctx, SymbolTable *s, Module *m, BasicBlock* bb=nullptr);
void visitFuncDef(ASTNode *ctx, SymbolTable *s, Module *m);
void visitBlock(ASTNode *ctx, SymbolTable *s, Module *m, Function* f, string f_name);

void visitConstDecl(ASTNode *ctx, SymbolTable *s, Module *m, BasicBlock* bb=nullptr);

// 与Syntax.h中的visitChildren函数逻辑相同，参数不同
void AST_NodeTraversal_IRGenerate(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb);